//
//  ComboBoxView.m
//  PlayBall
//
//  Created by Huawen Liu on 12-6-30.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddComboBoxView.h"
#import "JddCommonFunction.h"

@implementation JddComboBoxView
@synthesize dataListTable;
@synthesize tempArray;
@synthesize reslutArray;
@synthesize dataArray;
@synthesize delegate;
@synthesize commitButton;
@synthesize type;
@synthesize commitLabel;
GET_INSTANCE_VIEW_IMPLEMENT(JddComboBoxView)
-(IBAction)commit{
    [self dismissAnimated:YES];
    
//    [delegate performSelector:@selector(selectMatch:) withObject:reslutArray];
    [delegate selectMatch:reslutArray];
}

-(IBAction)selectout:(id)sender{
    [self dismissAnimated:YES];
}
//点击浮层里的cell会执行这里的代码
-(void)selectBoxValue:(NSString*)Value state:(NSNumber*)checked{
    self.selectedCellValue = Value;
    [dataListTable reloadData];
    if (type == 0) {
        if ([checked intValue]==0) {
            [reslutArray removeObject:Value];
        }else{
            [reslutArray addObject:Value];
        }
    } else if (type == 1){
        [self dismissAnimated:YES];
        /*
        [reslutArray addObject:Value];
         */
        [delegate performSelector:@selector(selectMatch:) withObject:Value];
    }
   
}



- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return DELETE;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [dataArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    JddComboBoxCell *cell = [JddComboBoxCell getInstanceView];
    
        for (NSString * string1  in reslutArray) {
            if ([string1 isEqualToString:[dataArray objectAtIndex:indexPath.row]]) {
                cell.imageView.image = [UIImage imageNamed:@"jdd_check"];
                cell.imageView.highlightedImage = [UIImage imageNamed:@"jdd_check_selected"];
                cell.myLable.textColor = [UIColor colorWithRed:33/256. green:80/256. blue:134/256. alpha:1];
                cell.checked = YES;
            }
        } 
     /*
    cell.imageView.image = nil;
    if ([self.selectedCellValue isEqualToString:[dataArray objectAtIndex:indexPath.row]]) {
        cell.imageView.image = [UIImage imageNamed:@"jdd_check"];
        //cell.imageView.highlightedImage = [UIImage imageNamed:@"jdd_check_selected"];
    }
    */
    cell.myLable.text = [dataArray objectAtIndex:indexPath.row];
    cell.delegate = self;
    cell.layer.cornerRadius = 8;
    
    return cell;
}

//- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
//    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//    //所有cell取消选择图像
//    self.selectedCellValue = [dataArray objectAtIndex:indexPath.row];
//    [dataListTable reloadData];
//    cell.imageView.image = [UIImage imageNamed:@"jdd_check"];
//}


- (void)loadContentView{
    reslutArray = [[NSMutableArray alloc] init];
    if ([tempArray count] ==0 ||tempArray == nil) {
        tempArray = [[NSMutableArray alloc] init];
    }else {
        for (NSNumber *num in tempArray) {
            [reslutArray addObject:num];
        }
    }
    dataListTable.layer.cornerRadius = 8;
    dataListTable.layer.masksToBounds = YES;
    dataListTable.showsVerticalScrollIndicator = NO;
    dataListTable.bounces = NO;
    _contentView = [JddComboBoxView getInstanceView];
    
    if (IOS7) {
        
    }else{
        dataListTable.backgroundColor = [UIColor whiteColor];
    }
    
    /*
    if (!reslutArray) {
        reslutArray = [[NSMutableArray alloc] init];
    }
    
    if ([tempArray count] ==0 ||tempArray == nil) {
        tempArray = [[NSMutableArray alloc] init];
    }else {
        for (NSNumber *num in tempArray) {
            [reslutArray addObject:num];
        }
    }
    dataListTable.layer.cornerRadius = 8;
    dataListTable.layer.masksToBounds = YES;
    dataListTable.showsVerticalScrollIndicator = NO;
    dataListTable.bounces = NO;
    
    _contentView = [JddComboBoxView getInstanceView];
    
    if (IOS7) {
        
    }else{
        dataListTable.backgroundColor = [UIColor whiteColor];
    }
    */
}

//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
//    return NO;
//}

@end
